define(
    ["PDUtilDir/grid", "PDUtilDir/util", "PDUtilDir/tool", "PDUtilDir/slidebar", "PDUtilDir/inputSelect", "PDUtilDir/fileupload/multiFileUpload", "Date", "DateCN", "css!DateCss"],
    function (Grid, Util, Tool, Slidebar, inputSelect, MFU) {
        function updateSupportInit($scope, $compile) {
            return new updateSupport($scope, $compile);
        };

        function updateSupport($scope, $compile) {
            this.$scope = $scope;
            this.$compile = $compile;
        };
        updateSupport.fn = updateSupport.prototype;

        updateSupport.fn.init = function (id) {
            var _this = this,
                allData = this.$scope.grid.getAllData();

            $.each(allData, function (index, row) {
                if (row.id == id) {
                    _this.entity = $.extend(row, {
                        carTypeName: _this.$scope.cache.typeMap.get(row.carType)
                    });
                    return;
                }
            });
        };

        updateSupport.fn.digest = function () {
            this.$scope.$digest();
        };

        updateSupport.fn.run = function (id) {
            var _this = this;
            _this.init(id);

            this.slidebars = Slidebar({
                size: 'lg',
                url: getServer()
                + "/static/app/fleet/cteamReserveInfos/views/update.html",
                $scope: this.$scope,
                $compile: this.$compile,
                afterLoad: function ($Panel) {
                    _this.initialization();
                    _this.digest();
                }
            });
        };
        updateSupport.fn.initialization = function () {
            this.baseInit();
            this.carInfoInit();
        };
        updateSupport.fn.baseInit = function () {
            var _this = this;
        };
        updateSupport.fn.save = function() {
            var _this = this;
            $.ajax({
                url : getServer() + "/flea/hclv/car/reserve/update/apply/add.htmls",
                data : {
                    'model' : JSON.stringify({
                        carReserveId: _this.entity.id,
                        updateTotalCost: _this.entity.totalCost
                    })
                },
                success : function(data) {
                    if (data.status != 200) {
                        return;
                    }
                    _this.$scope.grid.refresh();
                    Util.alert(data.message);
                    _this.slidebars.close();
                }
            });
        };
        updateSupport.fn.carInfoInit = function () {
            Grid({
                id : "CarTeamReserveDetailGirdDivId",
                pageSize : 10,
                index : true,
                multi : true,
                pagination : true,
                cache : false,
                layout : [ {
                    name : "车牌号",
                    field : "plateNumber",
                    sort : true
                }, {
                    name : "司机",
                    field : "driverName",
                    sort : true
                }, {
                    name : "司机电话",
                    field : "driverPhone"
                }, {
                    name : "创建时间",
                    field : "createTime"
                }],
                toolbar : [ ],
                data : {
                    type : "URL",
                    value : getServer()
                        + "/flea/hclv/car/reserve/getReserveCarItem.htmls"
                },
                queryParam: {
                    reserveCarId: this.entity.id
                }
            });
        };
        return updateSupportInit;
    });